package com.sinry.web.controller;

import cn.hutool.json.JSONObject;
import com.sinry.cache.service.Cache;
import com.sinry.web.responsitory.UserRepository;
import java.sql.SQLException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: XinLei
 * @Date: 2021/12/10 23:28
 */

@RestController
@RequestMapping("cache")
public class CacheController {
		
		@Autowired
		private Cache cache;
		@Autowired
		private UserRepository userRepository;
	
		@PutMapping("/set")
		public void set(@RequestBody JSONObject param) throws SQLException {
				cache.set((String)param.get("key"), userRepository.getUsers(), 5000L);
		}
	
		@GetMapping("/get/{key}")
		public Object get(@PathVariable String key) {
				return cache.get(key);
		}
}
